<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
    />
    <meta name="author" content="林镭特" />
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .topbox {
        width: 100%;
        height: 50px;
        background-color: #f0f0f0;
        text-align: center;
        line-height: 50px;
        border-bottom: 2px solid #ccc;
        font-weight: 900;
      }
      .content {
        width: 100%;
        height: 50px;
        text-align: center;
        line-height: 50px;
        border-bottom: 2px solid #ccc;
        background-color: #fff;
      }
      
    </style>
  </head>
  <body>
    <div id="app">
        <my-div :lists="lists"></my-div>
    </div>

    <script id="my-div" type="text/html">
      <div>
          <div v-for="(list, index) in lists" :key="index">
              <div class="topbox" @click="open($event,index)">{{list.title}}</div>
              <div v-if="lists[index].show">
                  <div  v-for="(name, index) in list.msg" :key="index" class='content'>{{name}}</div>
              </div>
          </div>
      </div>
    </script>

    <script>
      Vue.component("my-div", {
        template: "#my-div",
        props: ["lists"],
        data() {
          return {};
        },
        methods: {
          open(ev, index) {
            this.lists[index].show= !this.lists[index].show;
          },
        },
      });

      let app = new Vue({
        el: "#app",
        data: {
          lists: [
            {
              title: "家人",
              show: false,
              msg: ["爷爷", "奶奶", "爸爸"],
            },
            {
              title: "朋友",
              show: false,
              msg: ["吴彦祖", "刘德华", "周杰伦"],
            },
            {
              title: "同学",
              show: false,
              msg: ["黄渤", "黄磊", "吴京"],
            },
          ],
        },
      });
    </script>
  </body>
</html>
